package edu.uj.petri.view;

import edu.uj.petri.commands.Memento;
import edu.uj.petri.commands.Restorable;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

// TODO implement

class TokenView extends DiagramElement {
    private int tokenCount;
    private Point2D position;

    public TokenView( Point2D position ) {
        
        this.position = position;
    }

    public void draw(Canvas canvas) {
        
        canvas.drawText( Integer.toString(tokenCount), position);
    }

    public void setTokenCount(int count) {
        
        tokenCount = count;
    }

    public boolean containsPoint(Point2D point) {
        return false;
    }

    public boolean crossesRectangle(Rectangle2D rect) {
        return false;
    }

    public void setSelected(boolean selected) {
        //nic
    }

    public boolean canBeMoved(Point2D startPoint) {
        return false;
    }

    public void move(Point2D start, Point2D end) {
        
        Point2D difference = new Point2D.Double( start.getX() - end.getX(), start.getY() - end.getY());
        position.setLocation( position.getX() + difference.getX(), position.getY() + difference.getY());        
    }

    public void doubleClick( Point2D point ) {        
        
    }

    public ContextMenu getContextMenu() {
        return null;
    }

    public void removeFrom(View view) {
        // usuwa obiekt Place
    }

    public Memento getMemento() {
        TokenViewMemento retval = new TokenViewMemento();
        retval.position = (Point2D)position.clone();
        return retval;
    }

    public void applyMemento(Memento memento) {
        TokenViewMemento myMemento = (TokenViewMemento)memento;
        position = (Point2D)myMemento.position.clone();
    }
    
    static class TokenViewMemento extends Memento {
        private Point2D position;
    }
    
    private static final long serialVersionUID = 1064271951261685397L;
}
